﻿using System;
using System.Web.Configuration;
using System.Xml;
using UmbSearch2.Search;

namespace UmbSearch2
{
	public class Installer : umbraco.interfaces.IPackageAction
	{
		#region IPackageAction Members

		/// <summary>
		/// This alias will be used in the Package Action section. 
		/// Make sure that the alias in the xml matches the alias from the Class. 
		/// Otherwise umbraco will not execute this Package Action
		/// </summary>
		/// <returns></returns>
		public string Alias()
		{
			return "UmbSearch2";
		}

		/// <summary>
		/// This method will be executed on the install of this package
		/// </summary>
		public bool Execute(string packageName, System.Xml.XmlNode xmlData)
		{
			try
			{
				// insert reserved url
				System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/");
				string umbracoReservedPathsOld = configuration.AppSettings.Settings["umbracoReservedPaths"].Value;
				string umbracoReservedPathsNew = umbracoReservedPathsOld + ",/usercontrols/UmbSearch2/";
				configuration.AppSettings.Settings["umbracoReservedPaths"].Value = umbracoReservedPathsNew;
				configuration.Save();
			}
			catch 
			{}

			Indexer.ReIndex();
			return true;
		}

		public bool Undo(string packageName, XmlNode xmlData)
		{
			throw new NotImplementedException();
		}

		public XmlNode SampleXml()
		{
			throw new NotImplementedException();
		}

		

		#endregion
	}
}